const app = getApp()

Page({
  data: {
    flags: {},
    getInfo: false,
    useNumber: 0,
  },

  onLoad: function () {
    var that = this
    that.getConfig()
    var userinfo = wx.getStorageSync('brainpowerUserInfo');
    if (userinfo) {
      that.setData({
        getInfo: true
      })
    }
    var random = Math.floor(Math.random() * (50000 - 5000 + 1) + 10000);
    that.setData({
      useNumber: random
    })
  },

  getConfig: function () {
    var that = this
    wx.request({
      url: app.globalData.url + 'config/v/' + app.globalData.version,
      success: function (res) {
        that.setData({
          flags: res.data.data
        })

      }
    })
  },

  // 跳转答题页面
  toQuestion: function () {
    wx.navigateTo({
      url: "/pages/question/question"
    })
  },

  // 分享
  onShareAppMessage: function () {
    return {
      title: "@我 这题好难，快来帮帮我",
      imageUrl: '/images/share.jpg',
      pages: 'pages/index/index'
    }
  },

  onGotUserInfo: function (e) {
    app.globalData.userInfo = e.detail.userInfo
    wx.setStorage({
      key: 'brainpowerUserInfo',
      data: e.detail.userInfo,
      success: (res) => { }
    });
    this.toQuestion();
  },

  // 跳转盒子
  tohezi: function () {
    wx.navigateToMiniProgram({
      appId: 'wxa9002f27f3ed1519'
    });
  },
})